{% extends "../master.html" %}
{% block page_content %}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">内容审查</a>
        <a><cite>网站审查</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form layui-col-space5">
{#                        <!--{% raw xsrf_form_html() %}-->#}
                        <!--
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" id="id_task" name="taskname" placeholder="任务名" autocomplete="off" class="layui-input">
                        </div>
                        -->
                        <div class="layui-input-inline layui-show-xs-block">
                           <select name="contrller" id ='id_audit_task'>
                              <option value="">任务名</option>
                               {% for index, task_item in enumerate(task_list) %}
                                    <option value="{{ task_item.task_name}}">{{ task_item.task_name}}</option>
                               {% end %}
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="contrller" id ='id_audit_status'>
                              <option value="">机审类型</option>
                               {% for index, strategy_item in enumerate(strategy_list) %}
                                    <option value="{{ strategy_item.strategy_name}}">{{ strategy_item.strategy_name}}</option>
                               {% end %}
                            </select>
                        </div>
                    </form>
                    <div class="layui-input-inline layui-show-xs-block AuditTable">
                        <button class="layui-btn" lay-submit="" lay-filter="sreach" data-type="reload">
                            <i class="layui-icon">&#xe615;</i></button>
                    </div>
                </div>
                <xblock>
                    <div class="layui-card-header AuditTable">
                        <button type="button" class="layui-btn layui-btn-danger" id="task_delete" data-type="deletechoice">
                            <i class="layui-icon layui-icon-delete"></i>批量删除
                        </button>
                    </div>
                </xblock>
                <!--audit_table-->
                <div class="layui-card-body">
                    <table class="layui-table layui-form" id="audit_table" lay-filter="option"></table>
                </div>
                <!--end audit_table-->
            </div>
        </div>
    </div>
</div>
{% block sechfm_js %}
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="audit">审核</a>
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="whitelist">白名单</a>
      <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="block">加入阻断</a>
    </script>
{% end %}
<script>
//var xsrf = $('input[name="_xsrf"]').val();
layui.use('table', function() {
    var table = layui.table;
    //方法级渲染
    table.render({
        elem: '#audit_table'
        , url: "/audit/list"
        , method: 'post'
        //,where: {'xsrf_token':xsrf}
        , cols: [[
            {checkbox: true, fixed: true,width:80}
            , {field: 'taskname', title: '任务名',width:100}
            ,{field:'sitename', title: '站点名', style:"color:#00c3ff",width:130}
            ,{field: 'mode', title: '机审模式',width:100}
            ,{field: 'type', title: '机审类型',width:100}
            ,{field:'keywords', title: '关键词', sort: true,width:100}
            ,{field:'number', title: '数量', sort: true, style:"color:red", align:'center',event:'Number',width:100}
            ,{field: 'start_at', title: '最新监测时间', sort: true,width:160}
            ,{ title: '高级选项',fixed: 'right', align:'center', toolbar: '#barDemo'}
        ]]
        , id: 'testReload'
        , page: true
        , limit: 15
        , text: {none: '目前暂无数据'}
    });
    // 头工具事件栏
    table.on('tool(option)', function (obj) {
        //console.log(obj.event);
        if(obj.event === 'Number'){
            var data = obj.data.site_id;
            url = "/audit/num/SiteId";
            url = url.replace(/SiteId/,data);
            xadmin.open('违规站点列表',url);
        }else if(obj.event === 'audit'){
            console.log('审核')
        }else if(obj.event === 'whitelist'){
            console.log('加入白名单')
        }else if(obj.event === 'block'){
            console.log('加入阻断')
        }
    });
    // 操作
    var $ = layui.$, active = {
        // 删除任务
        deletechoice: function(){ //获取选中数据
            var checkStatus = table.checkStatus('testReload')
            ,data = checkStatus.data
            ,list=new Array();
            for(var i=0;i<data.length;i++){
                list[i] = data[i].taskname
            }
            layer.confirm('该操作为敏感操作<br>点击确认删除【'+data[0].taskname+'】该操作删除后无法恢复！',function(index){
                $.ajax({
                    type: "delete",
                    url: '',
                    async: true,
                    data:{
                        task_list:JSON.stringify(list),
                        action:'start',
                    },
                    success:function (data) {
                        layer.msg(data.msg);
                        setTimeout((function () {
                            location.replace(location.href)
                        }));
                    }
                });
            })
        }
        // 数据重载
        ,reload: function() {
            //执行重载
            //alert($('#id_task').val());
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    taskname: $('#id_audit_task').val()
                    ,status: $("#id_audit_status option:selected").val()
                }
            });
            }
        };
        $('.AuditTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


})
</script>


{% end %}